<!--评论管理页面-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>酒店后台管理系统</title>
    <link href="/resources/hotel/css/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="/resources/hotel/js/jquery.js"></script>
    <style type="text/css">
        .paginList li{
            margin-left: 50px;
        }
        input{
            border: #00a4ac 1px solid;
            height: 30px;
        }
        #reviewSelect li{
            float: left;
            text-align: center;
            padding-right: 10px;
            cursor: pointer;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function(){
            $(".click").click(function(){
                $(".tip").fadeIn(200);
            });

            $(".tiptop a").click(function(){
                $(".tip").fadeOut(200);
            });

            $(".sure").click(function(){
                $(".tip").fadeOut(100);
            });

            $(".cancel").click(function(){
                $(".tip").fadeOut(100);
            });

        });
    </script>
</head>


<body>

<div class="place">
    <span>位置：</span>
    <ul class="placeul">
        <li><a href="#">用户管理</a></li>
        <li><a href="#">评论管理</a></li>
    </ul>
</div>

<div class="rightinfo">
    <div class="formtitle" style="margin-top: 10px;color:#307fb1;"><span>评论管理</span></div>
    <table class="tablelist">
        <thead>
        <tr>
            <th>
                <ul  id="reviewSelect">
                    <li onclick="getReview(-1)">全部评论</li>
                    <li onclick="getReview(0)">好评</li>
                    <li onclick="getReview(1)">中评</li>
                    <li onclick="getReview(2)">差评</li>
                </ul>

            </th>
        </tr>
        </thead>
        <tbody id="tbody">

        </tbody>
    </table>


    <div class="pagin">
        <div class="message">共 <i class="blue" id="countData">0</i> 条记录，共 <i class="blue" id="countPage">0</i> 页，当前显示第&nbsp;<i class="blue" id="nowPage">0&nbsp;</i>页</div>
        <ul class="paginList" style="margin-right: 50px;">
            <li class="paginItem"><span><a href="#"  style="width: 70px;" id="upPage" onclick="flip(-1)">上一页</a></span></li>
            <li class="paginItem">
                <input id="finPageBox" type="text" style="width: 60px;height: 25px; " onkeypress="return event.keyCode>=48&&event.keyCode<=57" ng-pattern="/[^a-zA-Z]/"/>
                <button style="padding: 5px 10px;font-size: 12px;" id="findPageButton" onclick="flip(0)">跳转</button>
            </li>
            <li class="paginItem"><span><a href="#"  style="width: 70px;border: solid 1px lavender;" id="nextPage" onclick="flip(1)">下一页</a></span></li>
        </ul>
    </div>


    <div class="tip">
        <div class="tiptop"><span>提示信息</span><a></a></div>

        <div class="tipinfo">
            <span><img src="/resources/hotel/images/ticon.png" /></span>
            <div class="tipright">
                <p>是否确认对信息的修改 ？</p>
                <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
            </div>
        </div>

        <div class="tipbtn">
            <input name="" type="button"  class="sure" value="确定" />&nbsp;
            <input name="" type="button"  class="cancel" value="取消" />
        </div>

    </div>
</div>

<script type="text/javascript">
    $('.tablelist tbody tr:odd').addClass('odd');
</script>
<script type="text/javascript">
    //当前页数
    var nowPage;
    //总页数
    var countPage;

    //获取酒店所有订单信息
    getPage(1,-1);//页面加载，获取订单第一页
    /**
     * 翻页
     * @param flip -1上一页 0跳转页 1下一页
     */
    function flip(flip) {
        switch (flip){
            case -1:
                if(nowPage-1>0){
                    nowPage=nowPage-1;
                }else {
                    nowPage =1;
                    alert("已经是第一页了");
                }
                getPage(nowPage);//根据页码查询已完成订单
                break;
            case 0:
                var findPageNum = $("#finPageBox").val();
                if(findPageNum>0&&findPageNum<=countPage){
                    getPage(findPageNum);
                }else {
                    alert("页码错误!");
                }
                break;
            case 1:
                if((nowPage+1)*1<countPage){
                    nowPage=nowPage+1;
                }else {
                    nowPage =countPage;
                    alert("已经是最后一页了");
                }
                getPage(nowPage);//根据页码查询已完成订单
                break;
            default:
                alert("翻页请求错误！");
        }
    }

    function getPage(pageIndex,coType) {
        $.ajax({
            type: "get",
            url: "http://localhost:8080/merchant/queryallcomments",
            data:{
                "coType":coType,
                "pageIndex":pageIndex,
            },
            dataType: "json",
            success: function (JsonData) {
                nowPage = pageIndex;//设置当前页数
                $("#nowPage").html(nowPage);
                var data =JsonData;
                if(typeof JsonData == "string"){
                    data = JSON.parse(JsonData);
                }
                $("#countPage").html(data.pageNum);//设置总数据条数
                $("#countData").html(data.recordsNum);//设置总页数
                countPage = data.pageNum;

                if(data.success==true){
                    var tbody = $("#tbody");
                    tbody.html("");//清除以前的数据
                    var tr = "";
                    alert("成功响应！");
                    // for(var i=0;i<data.indents.length;i++){
                    //     var indents = data.indents[i];
                    //     tr = "<tr>"+
                    //         "<td>"+indents.iSequence+"</td>"+
                    //         "<td>"+indents.room.rName+"</td>"+
                    //         "<td>"+indents.room.rType.rtName+"</td>"+
                    //         "<td>"+timestampToTime(indents.iCreateTime)+"</td>"+
                    //         "<td>"+indents.room.rOriginalPrice+"</td>"+
                    //         "<td>"+indents.iAmount+"</td>"+
                    //         "<td>"+indents.iTotal+"</td>"+
                    //         "<td>"+timestampToTime(indents.iStart)+"</td>"+
                    //         "<td>"+timestampToTime(indents.iLeave)+"</td>"+
                    //         "<td>"+timestampToTime(indents.iLeave)+"</td>"+
                    //         "<td>"+indents.iUserName+"</td>"+
                    //         "<td>"+indents.iUserPhone+"</td>"+
                    //         "</tr>";
                    //     tbody.append(tr);
                    // }
                }else{
                    alert("没有查到评论信息");
                }

            },
            error: function () {
                alert("访问错误！");
            }
        });
    }
    //搜索的事件
    var sequence;
    var name;
    var start;
    var end
    $("#find").click(function () {
        sequence= $("#sequence").val();
        name= $("#name").val();
        start= $("#start").val();
        end= $("#end").val();
        if(start==null&&start==""){
            start="1970-01-01";
        }
        if(end==null&&end==""){
            end = getNowFormatDate();
        }
        getPage(1,sequence,name,start,end);
    });
    //获取当前时间，格式YYYY-MM-DD
    function getNowFormatDate() {
        var date = new Date();
        var seperator1 = "-";
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var strDate = date.getDate();
        if (month >= 1 && month <= 9) {
            month = "0" + month;
        }
        if (strDate >= 0 && strDate <= 9) {
            strDate = "0" + strDate;
        }
        var currentdate = year + seperator1 + month + seperator1 + strDate;
        return currentdate;
    }
    //将时间戳转换为时间格式YYY-MM-dd hh-mm-ss
    function timestampToTime(timestamp) {
        var date = new Date(timestamp);//时间戳为10位需*1000，时间戳为13位的话不需乘1000
        Y = date.getFullYear() + '-';
        M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
        D = date.getDate() + ' ';
        h = date.getHours() + ':';
        m = date.getMinutes() + ':';
        s = date.getSeconds();
        return Y+M+D+h+m+s;
    }
</script>
</body>
</html>
